function split(str, pat)
	local t = {}
	local last_end = 0
	local s, e = string.find(str, pat, 1)
	local i = 1
	while s do
		--print(str, s, e, last_end, s - last_end, string.sub(str, last_end + 1, last_end + s - last_end - 1))
		table.insert(t, string.sub(str, last_end + 1, last_end + s - last_end - 1))
		last_end = e
		--print(last_end)
		s, e = string.find(str, pat, last_end + 1)
		--print(s, e)
		i = i + 1
	end
	if last_end <= #str then
		cap = string.sub(str, last_end + 1)
		table.insert(t, cap)
	end
	return t
end


function print_array(array)
    print("{", table.concat(array, ', '), "}")
end


print_array(split("hello world", ' '))
print_array(split("aaaabbbbc", 'b'))
print_array(split("xxx", 'a'))
